import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/yt_table/yt_column_model.dart';
import 'package:yt_devops/components/yt_table/yt_profile_table.dart';
import 'package:yt_devops/pages/devices/device_tab/model/device_item_model.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'package:yt_devops/utils/formats.dart';

class CurrentType extends YtProfileTableData {
  String groupName;
  double? voltage;
  double? current;

  CurrentType({required this.groupName, this.voltage, this.current});

  @override
  Map<String, dynamic> toJson() {
    return {
      'groupName': groupName,
      'voltage': voltage,
      'current': current,
    };
  }
}

class PvInverterDetailModel {
  static TextStyle labelstyle =
      TextStyles.styleWith(14.sp, color: Colour.otherTextColor);
  static List<YtColumnModel<CurrentType>> inputColoums = [
    YtColumnModel<CurrentType>(
      title: ResKey.commonGroupString.tr, //  '组串',
      width: 76.w,
      field: 'groupName',
      render: (p, rowIndex) {
        return Text(
          p.groupName.toString(),
          style: TextStyles.styleWith(14.sp, color: Colour.otherTextColor),
        );
      },
    ),
    YtColumnModel<CurrentType>(
      title: ResKey.deviceInputVoltage.tr, //   '输入电压(V)',
      width: 145.w,
      field: 'voltage',
      render: (p, rowIndex) => Text(
        p.voltage != null
            ? double.parse(p.voltage.toString()).toStringAsFixed(2)
            : '--',
        style: TextStyles.f14,
      ),
    ),
    YtColumnModel<CurrentType>(
      title: ResKey.deviceInputCurrent.tr, //  '输入电流(A)',
      width: 121.w,
      field: 'current',
      render: (p, rowIndex) => Text(
        p.current != null
            ? double.parse(p.current.toString()).toStringAsFixed(2)
            : '--',
        style: TextStyles.f14,
      ),
    ),
  ];

  static List<YtColumnModel<CurrentType>> outputColoums = [
    YtColumnModel<CurrentType>(
      title: ResKey.commonGroupString.tr,
      width: 76.w,
      field: 'groupName',
      render: (p, rowIndex) {
        return Text(
          p.groupName.toString(),
          style: TextStyles.styleWith(14.sp, color: Colour.otherTextColor),
        );
      },
    ),
    YtColumnModel<CurrentType>(
      title: ResKey.deviceInputVoltage.tr, //   '电网电压(V)',
      width: 145.w,
      field: 'voltage',
      render: (p, rowIndex) => Text(
        p.voltage != null
            ? double.parse(p.voltage.toString()).toStringAsFixed(2)
            : '--',
        style: TextStyles.f14,
      ),
    ),
    YtColumnModel<CurrentType>(
      title: ResKey.deviceInputCurrent.tr, //  '电网电流(A)',
      width: 121.w,
      field: 'current',
      render: (p, rowIndex) => Text(
        p.current != null
            ? double.parse(p.current.toString()).toStringAsFixed(2)
            : '--',
        style: TextStyles.f14,
      ),
    ),
  ];

  List<Map<String, dynamic>> propertyList = [
    {
      'id': 'margin',
      'name': 'margin',
    },
    {
      'id': 'inverterState',
      'name': ResKey.deviceInverterState.tr // 逆变器状态
    },
    {
      'id': 'dayCap',
      'name': ResKey.deviceTodayElectricitygeneration.tr, //当日发电量
    },
    {
      'id': 'totalCap',
      'name': ResKey.siteOverviewGrandTotalPower.tr, //'累计发电量',
    },
    {
      'id': 'P',
      'name': ResKey.deviceActivePower.tr, //有功功率
    },
    {
      'id': 'reactivePower',
      'name': ResKey.deviceReactivePower.tr, //无功功率
    },
    {
      'id': 'ratedPowerOfInverter',
      'name': ResKey.deviceInverterRatedPower.tr, //  '逆变器额定功率',
    },
    {
      'id': 'powerFactor',
      'name': ResKey.devicePowerFactor.tr, //功率因数
    },
    {
      'id': 'elecFreq',
      'name': ResKey.deviceGridFrequency.tr, //  '电网频率',
    },
    {
      'id': 'margin',
      'name': 'margin',
    },
    {
      'id': 'openTime',
      'name': ResKey.deviceInverterStartupTime.tr, //   '逆变器开机时间',
    },
    {
      'id': 'closeTime',
      'name': ResKey.deviceInverterShutdownTime.tr, //    '逆变器关机时间',
    },
    {
      'id': 'margin',
      'name': 'margin',
    },
    {
      'id': 'outputMethod',
      'name': ResKey.deviceOutputMode.tr, //输出方式
    },
    {
      'id': 'temperature',
      'name': ResKey.deviceInternalTemperature.tr, //内部温度
    }
  ];
}
